package com.quanyan.user.web;

import com.quanyan.common.Plugin.PageObj;
import com.quanyan.user.model.db.TbAdminGroup;
import com.quanyan.user.model.vo.request.ReqQueryUserInfo;
import com.quanyan.user.model.vo.request.ReqQueryUserInterest;
import com.quanyan.user.model.vo.response.QueryUserDetail;
import com.quanyan.user.model.vo.response.QueryUserInfo;
import com.quanyan.user.model.vo.response.QueryUserInterest;
import com.quanyan.user.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * Created by yue.yuan on 2016/7/7.
 */
@RestController
@RequestMapping("/admin/api/user")
public class QueryUserController {

    @Autowired
    private AdminService adminService;

    @RequestMapping(value = "/interest/query/{isRegister}", method = RequestMethod.POST,produces="application/json")
    public PageObj<List<QueryUserInterest>> queryUserInterestList(HttpServletRequest request, @PathVariable boolean isRegister
            , @RequestBody @Valid ReqQueryUserInterest req, BindingResult bindingResult)
    {
        
        PageObj<List<QueryUserInterest>> result = adminService.selectUserInterestsByPage(req, isRegister);
        return result;
    }

    @RequestMapping(value = "/info/query", method = RequestMethod.POST,produces="application/json")
    public PageObj<List<QueryUserInfo>> queryUserInfoList(@RequestBody @Valid ReqQueryUserInfo req, BindingResult bindingResult)
    {
        PageObj<List<QueryUserInfo>> result = adminService.queryUserInfoByPage(req);
        return result;
    }

    @RequestMapping(value = "/detail/query", method = RequestMethod.POST,produces="application/json")
    public QueryUserDetail queryUserDetail(@RequestBody @Valid QueryUserInfo req, BindingResult bindingResult)
    {
        QueryUserDetail result = adminService.selectUserDetailById(req.getUserId());
        result.setQueryUserInfo(req);
        return result;
    }

    @RequestMapping(value = "/group/query", method = RequestMethod.POST,produces="application/json")
    public List<TbAdminGroup> queryUserInfoList()
    {
        return adminService.selectGroupList();
    }

    @RequestMapping(value = "/group/add", method = RequestMethod.POST,produces="application/json")
    public String queryUserInfoList(TbAdminGroup group)
    {
        adminService.addGroup(group);
        return "success";
    }

    @RequestMapping(value = "/group/delete", method = RequestMethod.POST,produces="application/json")
    public String queryUserInfoList(Integer groupId)
    {
        adminService.deleteGroup(groupId);
        return "success";
    }
}
